﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.ObjectModel;

namespace Sinacor.Infra.UI.Common
{
    public class EnumWrapperHelper
    {
        protected EnumWrapperHelper()
        { 
        
        }

        /// <summary>
        /// Retorna uma coleção de EnumWrappers com todos os enums
        /// </summary>
        /// <param name="type">Type do Enum</param>
        /// <returns>Coleção de EnumWrappers</returns>
        public static ObservableCollection<IEnumWrapper> GetEnums(Type type)
        {
            if (type == null)
                throw new ArgumentNullException("type");
            if (!type.IsEnum)
                throw new ArgumentException("The type is not an Enum", "type");

            ObservableCollection<IEnumWrapper> enums = new ObservableCollection<IEnumWrapper>();

            foreach (object v in Enum.GetValues(type))
            {
                IEnumWrapper enumWrapper = (IEnumWrapper)Activator.CreateInstance(Type.GetType("Sinacor.Infra.UI.Common.EnumWrapper`1").MakeGenericType(type), v);
                enums.Add(enumWrapper);
            }

            return enums;
        }

        /// <summary>
        /// Retorna uma coleção de EnumWrappers com os enums especificados
        /// </summary>
        /// <param name="type">Type do Enum</param>
        /// <param name="value">Valor dos enums</param>
        /// <returns>Coleção de EnumWrappers</returns>
        public static ObservableCollection<IEnumWrapper> GetEnums(Type type, params object[] value)
        {
            if (type == null)
                throw new ArgumentNullException("type");
            if (!type.IsEnum)
                throw new ArgumentException("The type is not an Enum", "type");
            if (value == null)
                throw new ArgumentNullException("value");

            ObservableCollection<IEnumWrapper> enums = new ObservableCollection<IEnumWrapper>();

            foreach (object v in value)
            {
                IEnumWrapper enumWrapper = (IEnumWrapper)Activator.CreateInstance(Type.GetType("Sinacor.Infra.UI.Common.EnumWrapper`1").MakeGenericType(type), v);
                enums.Add(enumWrapper);
            }

            return enums;
        }
    }
}
